package com.lrkj.workorder.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.workorder.domain.WorkOrderTemp;
import com.lrkj.workorder.service.IWorkOrderTempService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 工单模板Controller
 *
 * @author yajun_ren
 * @date 2022-04-18
 */
@RestController
@RequestMapping("/workorder/workOrderTemp")
@Api(tags = "工单模板")
public class WorkOrderTempController extends BaseController
{
    @Autowired
    private IWorkOrderTempService workOrderTempService;

    /**
     * 查询工单模板列表
     */
    @ApiOperation(value = "查询工单模板列表", notes = "查询工单模板列表")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderTemp:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrderTemp workOrderTemp)
    {
        startPage();
        this.changeParameter(workOrderTemp.getParams());
        List<WorkOrderTemp> list = workOrderTempService.selectWorkOrderTempList(workOrderTemp);
        return getDataTable(list);
    }

    /**
     * 导出工单模板列表
     */
	@ApiOperation(value = "导出工单模板列表", notes = "导出工单模板列表")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderTemp:export')")
    @Log(title = "工单模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkOrderTemp workOrderTemp)
    {
        List<WorkOrderTemp> list = workOrderTempService.selectWorkOrderTempList(workOrderTemp);
        ExcelUtil<WorkOrderTemp> util = new ExcelUtil<WorkOrderTemp>(WorkOrderTemp.class);
        return util.exportExcel(list, "工单模板数据");
    }

    /**
     * 获取工单模板详细信息
     */
	@ApiOperation(value = "获取工单模板详细信息", notes = "获取工单模板详细信息")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderTemp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(workOrderTempService.selectWorkOrderTempById(id));
    }

    /**
     * 新增工单模板
     */
    @ApiOperation(value = "新增工单模板", notes = "新增工单模板")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderTemp:add')")
    @Log(title = "工单模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrderTemp workOrderTemp)
    {
        return toAjax(workOrderTempService.insertWorkOrderTemp(workOrderTemp));
    }

    /**
     * 修改工单模板
     */
    @ApiOperation(value = "修改工单模板", notes = "修改工单模板")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderTemp:edit')")
    @Log(title = "工单模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrderTemp workOrderTemp)
    {
        return toAjax(workOrderTempService.updateWorkOrderTemp(workOrderTemp));
    }

    /**
     * 删除工单模板
     */
    @ApiOperation(value = "删除工单模板", notes = "删除工单模板")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderTemp:remove')")
    @Log(title = "工单模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(workOrderTempService.deleteWorkOrderTempByIds(ids));
    }
}
